﻿namespace WMS6.Web.Administration
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class UserPermissions : BasePage
    {
        protected HtmlAnchor BillingentityIsDefault;
        protected Button btnAddDetail;
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnDeleteDetail;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected HtmlAnchor CarrierIsDefault;
        protected HtmlAnchor CustomerIsDefault;
        protected HtmlForm F1031;
        protected GridView gvRole;
        protected HtmlInputHidden hdnAuthorizedBillingentity;
        protected HtmlInputHidden hdnAuthorizedCarrier;
        protected HtmlInputHidden hdnAuthorizedCustomer;
        protected HtmlInputHidden hdnAuthorizedOwner;
        protected HtmlInputHidden hdnAuthorizedVendor;
        protected HtmlInputHidden hdnAuthorizedWH;
        protected HtmlInputHidden hdnCurrentPage;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnPageSize;
        protected HtmlInputHidden hdnSortDirection;
        protected HtmlInputHidden hdnSortField;
        protected HtmlInputHidden hdnTotalPages;
        protected HtmlInputHidden hdnUnauthorizedBillingentity;
        protected HtmlInputHidden hdnUnauthorizedCarrier;
        protected HtmlInputHidden hdnUnauthorizedCustomer;
        protected HtmlInputHidden hdnUnauthorizedOwner;
        protected HtmlInputHidden hdnUnauthorizedVendor;
        protected HtmlInputHidden hdnUnauthorizedWH;
        protected HtmlHead Head1;
        protected ImageButton ImgAdd;
        protected ImageButton imgAuthorizedBillingentity;
        protected ImageButton imgAuthorizedCarrier;
        protected ImageButton imgAuthorizedCustomer;
        protected ImageButton imgAuthorizedOwner;
        protected ImageButton imgAuthorizedVendor;
        protected ImageButton ImgSub;
        protected ImageButton imgUnauthorizedBillingentity;
        protected ImageButton imgUnauthorizedCarrier;
        protected ImageButton imgUnauthorizedCustomer;
        protected ImageButton imgUnauthorizedOwner;
        protected ImageButton imgUnauthorizedVendor;
        protected HtmlAnchor isDefault;
        protected Label lblAuthorizedBillingentity;
        protected Label lblAuthorizedCarrier;
        protected Label lblAuthorizedCustomer;
        protected Label lblAuthorizedOwner;
        protected Label lblAuthorizedVendor;
        protected Label lblAuthorizedWH;
        protected Label lblMsg;
        protected Label lblOwner;
        protected Label lblUnauthorizedBillingentity;
        protected Label lblUnauthorizedCarrier;
        protected Label lblUnauthorizedCustomer;
        protected Label lblUnauthorizedOwner;
        protected Label lblUnauthorizedVendor;
        protected Label lblUnauthorizedWH;
        protected Label lblUomID;
        protected ListBox lbxAuthorizedBillingentity;
        protected ListBox lbxAuthorizedCarrier;
        protected ListBox lbxAuthorizedCustomer;
        protected ListBox lbxAuthorizedOwner;
        protected ListBox lbxAuthorizedVendor;
        protected ListBox lbxAuthorizedWH;
        protected ListBox lbxUnauthorizedBillingentity;
        protected ListBox lbxUnauthorizedCarrier;
        protected ListBox lbxUnauthorizedCustomer;
        protected ListBox lbxUnauthorizedOwner;
        protected ListBox lbxUnauthorizedVendor;
        protected ListBox lbxUnauthorizedWH;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected Label one6;
        protected Label one7;
        protected HtmlAnchor OwernIsDefault;
        protected ScriptManager ScriptManager1;
        protected TextBox txtUserID;
        protected UpdatePanel up1;
        protected HtmlAnchor VendorIsDefault;

        protected void btnBillingEntityIsDefault_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedBillingentity.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                foreach (UserBillingentityInfo info in userPermissions.AuthorizedBillingEntity)
                {
                    if (info.BillingentityID == this.hdnAuthorizedBillingentity.Value)
                    {
                        info.IsDefault = "Y";
                    }
                    else if (info.IsDefault == "Y")
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                    }
                }
                base.PageQueryEntitySession = userPermissions;
                this.SetControlslbxBillingEntityData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_032");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7,7) </script>", false);
        }

        protected void btnCarrierIsDefault_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedCarrier.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                foreach (UserCarrierInfo info in userPermissions.AuthorizedCarrier)
                {
                    if (info.CarrierID == this.hdnAuthorizedCarrier.Value)
                    {
                        info.IsDefault = "Y";
                    }
                    else if (info.IsDefault == "Y")
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                    }
                }
                base.PageQueryEntitySession = userPermissions;
                this.SetControlslbxCarrierData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_025");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',6,7) </script>", false);
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtUserID.Text = "";
            this.txtUserID.Enabled = true;
            base.DataEntityViewState = null;
        }

        protected void btnCustomerIsDefault_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedCustomer.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                foreach (UserCustomerInfo info in userPermissions.AuthorizedCustomer)
                {
                    if (info.CustomerID == this.hdnAuthorizedCustomer.Value)
                    {
                        info.IsDefault = "Y";
                    }
                    else if (info.IsDefault == "Y")
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                    }
                }
                base.PageQueryEntitySession = userPermissions;
                this.SetControlslbxCustomerData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_024");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,7) </script>", false);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtUserID.Text.Trim()))
            {
                try
                {
                    List<string> userID = new List<string> {
                        this.txtUserID.Text.Trim()
                    };
                    if (BaseInfoServiceClientProxy.GetInstance().Delete(userID, "USER_PERMISSIONS") != "0")
                    {
                        this.lblMsg.Text = this.txtUserID.Text + base.GetGlobalMsgResource("F1300_006");
                    }
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnCopy.Enabled = false;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F1300_007") + ex.Message;
                }
            }
        }

        protected void btnDeleteDetail_Click(object sender, EventArgs e)
        {
            List<string> selectedID = base.GetSelectedIDsInGridView(this.gvRole, "RoleID");
            if ((selectedID == null) || (selectedID.Count == 0))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_008");
            }
            else if (this.ClearUserRoleByRoleID(selectedID))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                this.SetControlsGvRoleData(userPermissions);
                this.SetControlslbxWhData(userPermissions);
                this.SetControlslbxOwnerData(userPermissions);
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_009");
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            string from = this.hdnFrom.Value;
            if (from == "query")
            {
                base.Response.Redirect("UserPermissionsQuery.aspx", false);
            }
            else if (from == "list")
            {
                base.Response.Redirect("UserPermissionsList.aspx?from=edit", false);
            }
            else
            {
                base.Response.Redirect("UserPermissionsList.aspx?from=edit", false);
            }
        }

        protected void btnOwernIsDefault_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedOwner.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                foreach (OwnerInfo info in userPermissions.AuthorizedOwner)
                {
                    if (info.OwnerID == this.hdnAuthorizedOwner.Value)
                    {
                        info.IsDefault = "Y";
                    }
                    else if (info.IsDefault == "Y")
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                    }
                }
                base.PageQueryEntitySession = userPermissions;
                this.SetControlslbxOwnerData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_026");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,7) </script>", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
            if (userPermissions != null)
            {
                if (userPermissions.AuthorizedWH.Count > 0)
                {
                    try
                    {
                        this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Update(userPermissions, "USER_PERMISSIONS") + base.GetGlobalMsgResource("F1300_003");
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F1300_004") + ex.Message;
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F1300_005");
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,7) </script>", false);
                }
            }
        }

        protected void btnVendorIsDefault_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedVendor.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                foreach (UserVendorInfo info in userPermissions.AuthorizedVendor)
                {
                    if (info.VendorID == this.hdnAuthorizedVendor.Value)
                    {
                        info.IsDefault = "Y";
                    }
                    else if (info.IsDefault == "Y")
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                    }
                }
                base.PageQueryEntitySession = userPermissions;
                this.SetControlslbxVendorData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_025");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5,7) </script>", false);
        }

        protected void btnWhIsDefault_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedWH.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<DbConfigInfo> dbConfig = new List<DbConfigInfo>();
                foreach (DbConfigInfo info in userPermissions.AuthorizedWH)
                {
                    if (info.WhDbID.ToString() == this.hdnAuthorizedWH.Value)
                    {
                        info.IsDefault = "Y";
                    }
                    else if (info.IsDefault == "Y")
                    {
                        info.IsDefault = "N";
                        info.WhDbDesc = info.WhDbDesc.Replace(" ★ ", "");
                    }
                }
                base.PageQueryEntitySession = userPermissions;
                this.SetControlslbxWhData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_012");
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,7) </script>", false);
        }

        private bool ClearUserRoleByRoleID(List<string> roleId)
        {
            UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
            List<UserRoleInfo> userRoleInfo = userPermissions.UserRoleInfo;
            try
            {
                for (int i = 0; roleId.Count > i; i++)
                {
                    foreach (UserRoleInfo info in userPermissions.UserRoleInfo)
                    {
                        if (info.RoleID == roleId[i])
                        {
                            userRoleInfo.Remove(info);
                            break;
                        }
                    }
                }
                userPermissions.UserRoleInfo = userRoleInfo;
                base.PageQueryEntitySession = userPermissions;
                return true;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_007") + ex.Message;
                return false;
            }
        }

        protected void gvRole_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F1031", this.gvRole);
        }

        protected void gvRole_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.PageQueryEntitySession as UserPermissionsInfo).UserRoleInfo;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',1,7) </script>", false);
        }

        protected void gvRole_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((int.Parse(this.hdnCurrentPage.Value) * int.Parse(this.hdnPageSize.Value)) + e.Row.RowIndex) + 1).ToString();
            }
        }

        protected void ImgAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedWH.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<DbConfigInfo> dbConfig = new List<DbConfigInfo>();
                string[] strAuthorizedWH = this.hdnAuthorizedWH.Value.Split(new char[] { ';' });
                foreach (DbConfigInfo info in userPermissions.AuthorizedWH)
                {
                    bool istrue = false;
                    for (int i = 0; strAuthorizedWH.Length > i; i++)
                    {
                        if (info.WhDbID.ToString() == strAuthorizedWH[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        info.IsDefault = "N";
                        info.WhDbDesc = info.WhDbDesc.Replace(" ★ ", "");
                        userPermissions.UnauthorizedWH.Add(info);
                    }
                    else
                    {
                        dbConfig.Add(info);
                    }
                }
                userPermissions.AuthorizedWH = dbConfig;
                base.PageQueryEntitySession = userPermissions;
                this.hdnAuthorizedWH.Value = string.Empty;
                this.SetControlslbxWhData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_010");
            }
            if (this.lbxAuthorizedWH.Items.Count > 0)
            {
                this.lbxAuthorizedWH.Items[0].Selected = true;
                this.lbxAuthorizedWH_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,7) </script>", false);
        }

        protected void imgAuthorizedBillingEntity_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedBillingentity.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserBillingentityInfo> userBillingEntityInfo = new List<UserBillingentityInfo>();
                string[] strAuthorizedBillingentity = this.hdnAuthorizedBillingentity.Value.Split(new char[] { ';' });
                foreach (UserBillingentityInfo info in userPermissions.AuthorizedBillingEntity)
                {
                    bool istrue = false;
                    for (int i = 0; strAuthorizedBillingentity.Length > i; i++)
                    {
                        if (info.BillingentityID == strAuthorizedBillingentity[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                        userPermissions.UnauthorizedBillingEntity.Add(info);
                    }
                    else
                    {
                        userBillingEntityInfo.Add(info);
                    }
                }
                userPermissions.AuthorizedBillingEntity = userBillingEntityInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnAuthorizedBillingentity.Value = string.Empty;
                this.SetControlslbxBillingEntityData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_031");
            }
            if (this.lbxAuthorizedBillingentity.Items.Count > 0)
            {
                this.lbxAuthorizedBillingentity.Items[0].Selected = true;
                this.lbxAuthorizedBillingEntity_SelectedIndexChanged(sender, e);
            }
            this.hdnAuthorizedBillingentity.Value = "";
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7,7) </script>", false);
        }

        protected void imgAuthorizedCarrier_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedCarrier.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserCarrierInfo> userCarrierInfo = new List<UserCarrierInfo>();
                string[] strAuthorizedCarrier = this.hdnAuthorizedCarrier.Value.Split(new char[] { ';' });
                foreach (UserCarrierInfo info in userPermissions.AuthorizedCarrier)
                {
                    bool istrue = false;
                    for (int i = 0; strAuthorizedCarrier.Length > i; i++)
                    {
                        if (info.CarrierID == strAuthorizedCarrier[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                        userPermissions.UnauthorizedCarrier.Add(info);
                    }
                    else
                    {
                        userCarrierInfo.Add(info);
                    }
                }
                userPermissions.AuthorizedCarrier = userCarrierInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnAuthorizedCarrier.Value = string.Empty;
                this.SetControlslbxCarrierData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_027");
            }
            if (this.lbxAuthorizedCarrier.Items.Count > 0)
            {
                this.lbxAuthorizedCarrier.Items[0].Selected = true;
                this.lbxAuthorizedCarrier_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',6,7) </script>", false);
        }

        protected void imgAuthorizedCustomer_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedCustomer.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserCustomerInfo> userCustomerInfo = new List<UserCustomerInfo>();
                string[] strAuthorizedCustomer = this.hdnAuthorizedCustomer.Value.Split(new char[] { ';' });
                foreach (UserCustomerInfo info in userPermissions.AuthorizedCustomer)
                {
                    bool istrue = false;
                    for (int i = 0; strAuthorizedCustomer.Length > i; i++)
                    {
                        if (info.CustomerID == strAuthorizedCustomer[i])
                        {
                            istrue = true;
                        }
                    }
                    if (istrue)
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                        userPermissions.UnauthorizedCustomer.Add(info);
                    }
                    else
                    {
                        userCustomerInfo.Add(info);
                    }
                }
                userPermissions.AuthorizedCustomer = userCustomerInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnAuthorizedCustomer.Value = string.Empty;
                this.SetControlslbxCustomerData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_018");
            }
            if (this.lbxAuthorizedCustomer.Items.Count > 0)
            {
                this.lbxAuthorizedCustomer.Items[0].Selected = true;
                this.lbxAuthorizedCustomer_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,7) </script>", false);
        }

        protected void imgAuthorizedOwner_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedOwner.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                string[] strAuthorizedOwner = this.hdnAuthorizedOwner.Value.Split(new char[] { ';' });
                foreach (OwnerInfo info in userPermissions.AuthorizedOwner)
                {
                    bool istrue = false;
                    for (int i = 0; strAuthorizedOwner.Length > i; i++)
                    {
                        if (info.OwnerID == strAuthorizedOwner[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                        userPermissions.UnauthorizedOwner.Add(info);
                    }
                    else
                    {
                        ownerInfo.Add(info);
                    }
                }
                userPermissions.AuthorizedOwner = ownerInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnAuthorizedOwner.Value = string.Empty;
                this.SetControlslbxOwnerData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_011");
            }
            if (this.lbxAuthorizedOwner.Items.Count > 0)
            {
                this.lbxAuthorizedOwner.Items[0].Selected = true;
                this.lbxAuthorizedOwner_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,7) </script>", false);
        }

        protected void imgAuthorizedVendor_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedVendor.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserVendorInfo> userVendorInfo = new List<UserVendorInfo>();
                string[] strAuthorizedVendor = this.hdnAuthorizedVendor.Value.Split(new char[] { ';' });
                foreach (UserVendorInfo info in userPermissions.AuthorizedVendor)
                {
                    bool istrue = false;
                    for (int i = 0; strAuthorizedVendor.Length > i; i++)
                    {
                        if (info.VendorID == strAuthorizedVendor[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        info.IsDefault = "N";
                        info.Company = info.Company.Replace(" ★ ", "");
                        userPermissions.UnauthorizedVendor.Add(info);
                    }
                    else
                    {
                        userVendorInfo.Add(info);
                    }
                }
                userPermissions.AuthorizedVendor = userVendorInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnAuthorizedVendor.Value = string.Empty;
                this.SetControlslbxVendorData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_022");
            }
            if (this.lbxAuthorizedVendor.Items.Count > 0)
            {
                this.lbxAuthorizedVendor.Items[0].Selected = true;
                this.lbxAuthorizedVendor_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5,7) </script>", false);
        }

        protected void ImgSub_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedWH.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<DbConfigInfo> dbConfig = new List<DbConfigInfo>();
                string[] strUnauthorizedWH = this.hdnUnauthorizedWH.Value.Split(new char[] { ';' });
                foreach (DbConfigInfo info in userPermissions.UnauthorizedWH)
                {
                    bool istrue = false;
                    for (int i = 0; strUnauthorizedWH.Length > i; i++)
                    {
                        if (info.WhDbID.ToString() == strUnauthorizedWH[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        userPermissions.AuthorizedWH.Add(info);
                    }
                    else
                    {
                        dbConfig.Add(info);
                    }
                }
                userPermissions.UnauthorizedWH = dbConfig;
                base.PageQueryEntitySession = userPermissions;
                this.hdnUnauthorizedWH.Value = string.Empty;
                this.SetControlslbxWhData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_019");
            }
            if (this.lbxUnauthorizedWH.Items.Count > 0)
            {
                this.lbxUnauthorizedWH.Items[0].Selected = true;
                this.lbxUnauthorizedWH_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,7) </script>", false);
        }

        protected void imgUnauthorizedBillingEntity_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedBillingentity.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserBillingentityInfo> userBillingEntityInfo = new List<UserBillingentityInfo>();
                string[] strUnauthorizedBillingentity = this.hdnUnauthorizedBillingentity.Value.Split(new char[] { ';' });
                foreach (UserBillingentityInfo info in userPermissions.UnauthorizedBillingEntity)
                {
                    bool istrue = false;
                    for (int i = 0; strUnauthorizedBillingentity.Length > i; i++)
                    {
                        if (info.BillingentityID == strUnauthorizedBillingentity[i])
                        {
                            istrue = true;
                        }
                    }
                    if (istrue)
                    {
                        userPermissions.AuthorizedBillingEntity.Add(info);
                    }
                    else
                    {
                        userBillingEntityInfo.Add(info);
                    }
                }
                userPermissions.UnauthorizedBillingEntity = userBillingEntityInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnUnauthorizedBillingentity.Value = string.Empty;
                this.SetControlslbxBillingEntityData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_032");
            }
            if (this.lbxUnauthorizedBillingentity.Items.Count > 0)
            {
                this.lbxUnauthorizedBillingentity.Items[0].Selected = true;
                this.lbkUnauthorizedBillingEntity_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7,7) </script>", false);
        }

        protected void imgUnauthorizedCarrier_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedCarrier.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserCarrierInfo> userCarrierInfo = new List<UserCarrierInfo>();
                string[] strUnauthorizedCarrier = this.hdnUnauthorizedCarrier.Value.Split(new char[] { ';' });
                foreach (UserCarrierInfo info in userPermissions.UnauthorizedCarrier)
                {
                    bool istrue = false;
                    for (int i = 0; strUnauthorizedCarrier.Length > i; i++)
                    {
                        if (info.CarrierID == strUnauthorizedCarrier[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        userPermissions.AuthorizedCarrier.Add(info);
                    }
                    else
                    {
                        userCarrierInfo.Add(info);
                    }
                }
                userPermissions.UnauthorizedCarrier = userCarrierInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnUnauthorizedCarrier.Value = string.Empty;
                this.SetControlslbxCarrierData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_028");
            }
            if (this.lbxUnauthorizedCarrier.Items.Count > 0)
            {
                this.lbxUnauthorizedCarrier.Items[0].Selected = true;
                this.lbkUnauthorizedCarrier_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',6,7) </script>", false);
        }

        protected void imgUnauthorizedCustomer_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedCustomer.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserCustomerInfo> userCustomerInfo = new List<UserCustomerInfo>();
                string[] strUnauthorizedCustomer = this.hdnUnauthorizedCustomer.Value.Split(new char[] { ';' });
                foreach (UserCustomerInfo info in userPermissions.UnauthorizedCustomer)
                {
                    bool istrue = false;
                    for (int i = 0; strUnauthorizedCustomer.Length > i; i++)
                    {
                        if (info.CustomerID == strUnauthorizedCustomer[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        userPermissions.AuthorizedCustomer.Add(info);
                    }
                    else
                    {
                        userCustomerInfo.Add(info);
                    }
                }
                userPermissions.UnauthorizedCustomer = userCustomerInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnUnauthorizedCustomer.Value = string.Empty;
                this.SetControlslbxCustomerData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_019");
            }
            if (this.lbxUnauthorizedCustomer.Items.Count > 0)
            {
                this.lbxUnauthorizedCustomer.Items[0].Selected = true;
                this.lbkUnauthorizedCustomer_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,7) </script>", false);
        }

        protected void imgUnauthorizedOwner_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedOwner.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<OwnerInfo> ownerInfo = new List<OwnerInfo>();
                string[] strUnauthorizedOwner = this.hdnUnauthorizedOwner.Value.Split(new char[] { ';' });
                foreach (OwnerInfo info in userPermissions.UnauthorizedOwner)
                {
                    bool istrue = false;
                    for (int i = 0; strUnauthorizedOwner.Length > i; i++)
                    {
                        if (info.OwnerID == strUnauthorizedOwner[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        userPermissions.AuthorizedOwner.Add(info);
                    }
                    else
                    {
                        ownerInfo.Add(info);
                    }
                }
                userPermissions.UnauthorizedOwner = ownerInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnUnauthorizedOwner.Value = string.Empty;
                this.SetControlslbxOwnerData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_020");
            }
            if (this.lbxUnauthorizedOwner.Items.Count > 0)
            {
                this.lbxUnauthorizedOwner.Items[0].Selected = true;
                this.lbkUnauthorizedOwner_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,7) </script>", false);
        }

        protected void imgUnauthorizedVendor_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedVendor.Value))
            {
                UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
                List<UserVendorInfo> userVendorInfo = new List<UserVendorInfo>();
                string[] strUnauthorizedVendor = this.hdnUnauthorizedVendor.Value.Split(new char[] { ';' });
                foreach (UserVendorInfo info in userPermissions.UnauthorizedVendor)
                {
                    bool istrue = false;
                    for (int i = 0; strUnauthorizedVendor.Length > i; i++)
                    {
                        if (info.VendorID == strUnauthorizedVendor[i])
                        {
                            istrue = true;
                            break;
                        }
                    }
                    if (istrue)
                    {
                        userPermissions.AuthorizedVendor.Add(info);
                    }
                    else
                    {
                        userVendorInfo.Add(info);
                    }
                }
                userPermissions.UnauthorizedVendor = userVendorInfo;
                base.PageQueryEntitySession = userPermissions;
                this.hdnUnauthorizedVendor.Value = string.Empty;
                this.SetControlslbxVendorData(userPermissions);
            }
            else
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text = base.GetGlobalMsgResource("F1300_023");
            }
            if (this.lbxUnauthorizedVendor.Items.Count > 0)
            {
                this.lbxUnauthorizedVendor.Items[0].Selected = true;
                this.lbkUnauthorizedVendor_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5,7) </script>", false);
        }

        protected void lbkUnauthorizedBillingEntity_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedBillingentity.Value = "";
            if (this.lbxUnauthorizedBillingentity.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedBillingentity.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedBillingentity.Value = this.hdnUnauthorizedBillingentity.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedCarrier.Value))
                {
                    this.hdnUnauthorizedBillingentity.Value = this.hdnUnauthorizedBillingentity.Value.Substring(0, this.hdnUnauthorizedBillingentity.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7,7) </script>", false);
        }

        protected void lbkUnauthorizedCarrier_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedCarrier.Value = "";
            if (this.lbxUnauthorizedCarrier.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedCarrier.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedCarrier.Value = this.hdnUnauthorizedCarrier.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedCarrier.Value))
                {
                    this.hdnUnauthorizedCarrier.Value = this.hdnUnauthorizedCarrier.Value.Substring(0, this.hdnUnauthorizedCarrier.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',6,7) </script>", false);
        }

        protected void lbkUnauthorizedCustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedCustomer.Value = "";
            if (this.lbxUnauthorizedCustomer.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedCustomer.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedCustomer.Value = this.hdnUnauthorizedCustomer.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedCustomer.Value))
                {
                    this.hdnUnauthorizedCustomer.Value = this.hdnUnauthorizedCustomer.Value.Substring(0, this.hdnUnauthorizedCustomer.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,7) </script>", false);
        }

        protected void lbkUnauthorizedOwner_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedOwner.Value = "";
            if (this.lbxUnauthorizedOwner.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedOwner.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedOwner.Value = this.hdnUnauthorizedOwner.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedOwner.Value))
                {
                    this.hdnUnauthorizedOwner.Value = this.hdnUnauthorizedOwner.Value.Substring(0, this.hdnUnauthorizedOwner.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,7) </script>", false);
        }

        protected void lbkUnauthorizedVendor_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedVendor.Value = "";
            if (this.lbxUnauthorizedVendor.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedVendor.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedVendor.Value = this.hdnUnauthorizedVendor.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedVendor.Value))
                {
                    this.hdnUnauthorizedVendor.Value = this.hdnUnauthorizedVendor.Value.Substring(0, this.hdnUnauthorizedVendor.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5,7) </script>", false);
        }

        protected void lbxAuthorizedBillingEntity_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedBillingentity.Value = "";
            if (this.lbxAuthorizedBillingentity.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedBillingentity.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedBillingentity.Value = this.hdnAuthorizedBillingentity.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedCarrier.Value))
                {
                    this.hdnAuthorizedBillingentity.Value = this.hdnAuthorizedBillingentity.Value.Substring(0, this.hdnAuthorizedBillingentity.Value.Length - 1);
                }
            }
            this.BillingentityIsDefault.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7,7) </script>", false);
        }

        protected void lbxAuthorizedCarrier_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedCarrier.Value = "";
            if (this.lbxAuthorizedCarrier.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedCarrier.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedCarrier.Value = this.hdnAuthorizedCarrier.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedCarrier.Value))
                {
                    this.hdnAuthorizedCarrier.Value = this.hdnAuthorizedCarrier.Value.Substring(0, this.hdnAuthorizedCarrier.Value.Length - 1);
                }
            }
            this.CarrierIsDefault.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',6,7) </script>", false);
        }

        protected void lbxAuthorizedCustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedCustomer.Value = "";
            if (this.lbxAuthorizedCustomer.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedCustomer.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedCustomer.Value = this.hdnAuthorizedCustomer.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedCustomer.Value))
                {
                    this.hdnAuthorizedCustomer.Value = this.hdnAuthorizedCustomer.Value.Substring(0, this.hdnAuthorizedCustomer.Value.Length - 1);
                }
            }
            this.CustomerIsDefault.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',4,7) </script>", false);
        }

        protected void lbxAuthorizedOwner_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedOwner.Value = "";
            if (this.lbxAuthorizedOwner.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedOwner.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedOwner.Value = this.hdnAuthorizedOwner.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedOwner.Value))
                {
                    this.hdnAuthorizedOwner.Value = this.hdnAuthorizedOwner.Value.Substring(0, this.hdnAuthorizedOwner.Value.Length - 1);
                }
            }
            this.OwernIsDefault.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',3,7) </script>", false);
        }

        protected void lbxAuthorizedVendor_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedVendor.Value = "";
            if (this.lbxAuthorizedVendor.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedVendor.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedVendor.Value = this.hdnAuthorizedVendor.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedVendor.Value))
                {
                    this.hdnAuthorizedVendor.Value = this.hdnAuthorizedVendor.Value.Substring(0, this.hdnAuthorizedVendor.Value.Length - 1);
                }
            }
            this.VendorIsDefault.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',5,7) </script>", false);
        }

        protected void lbxAuthorizedWH_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedWH.Value = "";
            if (this.lbxAuthorizedWH.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedWH.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedWH.Value = this.hdnAuthorizedWH.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedWH.Value))
                {
                    this.hdnAuthorizedWH.Value = this.hdnAuthorizedWH.Value.Substring(0, this.hdnAuthorizedWH.Value.Length - 1);
                }
            }
            this.isDefault.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,7) </script>", false);
        }

        protected void lbxUnauthorizedWH_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedWH.Value = "";
            if (this.lbxUnauthorizedWH.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedWH.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedWH.Value = this.hdnUnauthorizedWH.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedWH.Value))
                {
                    this.hdnUnauthorizedWH.Value = this.hdnUnauthorizedWH.Value.Substring(0, this.hdnUnauthorizedWH.Value.Length - 1);
                }
            }
            this.isDefault.Visible = false;
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,7) </script>", false);
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.SetUserPermissionsInfo2Form(base.Request.QueryString["ID"].ToString());
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"];
                if (base.Request.QueryString["from"] == "detail")
                {
                    this.SetUserPermissionsInfo3From();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
            this.lblMsg.Text = "";
        }

        private void SetControlsGvRoleData(UserPermissionsInfo userPermission)
        {
            base.BindData2GridView(this.gvRole, userPermission.UserRoleInfo);
        }

        private void SetControlslbxBillingEntityData(UserPermissionsInfo userPermission)
        {
            this.lbxAuthorizedBillingentity.Items.Clear();
            foreach (UserBillingentityInfo info in userPermission.AuthorizedBillingEntity)
            {
                ListItem item = new ListItem {
                    Value = info.BillingentityID
                };
                if (info.IsDefault == "Y")
                {
                    item.Text = info.Company + " ★ ";
                }
                else
                {
                    item.Text = info.Company;
                }
                this.lbxAuthorizedBillingentity.Items.Add(item);
            }
            this.lbxUnauthorizedBillingentity.DataSource = userPermission.UnauthorizedBillingEntity;
            this.lbxUnauthorizedBillingentity.DataTextField = "Company";
            this.lbxUnauthorizedBillingentity.DataValueField = "BillingentityID";
            this.lbxUnauthorizedBillingentity.DataBind();
        }

        private void SetControlslbxCarrierData(UserPermissionsInfo userPermission)
        {
            this.lbxAuthorizedCarrier.Items.Clear();
            foreach (UserCarrierInfo info in userPermission.AuthorizedCarrier)
            {
                ListItem item = new ListItem {
                    Value = info.CarrierID
                };
                if (info.IsDefault == "Y")
                {
                    item.Text = info.Company + " ★ ";
                }
                else
                {
                    item.Text = info.Company;
                }
                this.lbxAuthorizedCarrier.Items.Add(item);
            }
            this.lbxUnauthorizedCarrier.DataSource = userPermission.UnauthorizedCarrier;
            this.lbxUnauthorizedCarrier.DataTextField = "Company";
            this.lbxUnauthorizedCarrier.DataValueField = "CarrierID";
            this.lbxUnauthorizedCarrier.DataBind();
        }

        private void SetControlslbxCustomerData(UserPermissionsInfo userPermission)
        {
            this.lbxAuthorizedCustomer.Items.Clear();
            foreach (UserCustomerInfo info in userPermission.AuthorizedCustomer)
            {
                ListItem item = new ListItem {
                    Value = info.CustomerID
                };
                if (info.IsDefault == "Y")
                {
                    item.Text = info.Company + " ★ ";
                }
                else
                {
                    item.Text = info.Company;
                }
                this.lbxAuthorizedCustomer.Items.Add(item);
            }
            this.lbxUnauthorizedCustomer.DataSource = userPermission.UnauthorizedCustomer;
            this.lbxUnauthorizedCustomer.DataTextField = "Company";
            this.lbxUnauthorizedCustomer.DataValueField = "CustomerID";
            this.lbxUnauthorizedCustomer.DataBind();
        }

        private void SetControlslbxOwnerData(UserPermissionsInfo userPermission)
        {
            this.lbxAuthorizedOwner.Items.Clear();
            foreach (OwnerInfo info in userPermission.AuthorizedOwner)
            {
                ListItem item = new ListItem {
                    Value = info.OwnerID
                };
                if (info.IsDefault == "Y")
                {
                    item.Text = info.Company + " ★ ";
                }
                else
                {
                    item.Text = info.Company;
                }
                this.lbxAuthorizedOwner.Items.Add(item);
            }
            this.lbxUnauthorizedOwner.DataSource = userPermission.UnauthorizedOwner;
            this.lbxUnauthorizedOwner.DataTextField = "Company";
            this.lbxUnauthorizedOwner.DataValueField = "OwnerID";
            this.lbxUnauthorizedOwner.DataBind();
        }

        private void SetControlslbxVendorData(UserPermissionsInfo userPermission)
        {
            this.lbxAuthorizedVendor.Items.Clear();
            foreach (UserVendorInfo info in userPermission.AuthorizedVendor)
            {
                ListItem item = new ListItem {
                    Value = info.VendorID
                };
                if (info.IsDefault == "Y")
                {
                    item.Text = info.Company + " ★ ";
                }
                else
                {
                    item.Text = info.Company;
                }
                this.lbxAuthorizedVendor.Items.Add(item);
            }
            this.lbxUnauthorizedVendor.DataSource = userPermission.UnauthorizedVendor;
            this.lbxUnauthorizedVendor.DataTextField = "Company";
            this.lbxUnauthorizedVendor.DataValueField = "VendorID";
            this.lbxUnauthorizedVendor.DataBind();
        }

        private void SetControlslbxWhData(UserPermissionsInfo userPermission)
        {
            this.lbxAuthorizedWH.Items.Clear();
            foreach (DbConfigInfo info in userPermission.AuthorizedWH)
            {
                ListItem item = new ListItem {
                    Value = info.WhDbID.ToString()
                };
                if (info.IsDefault == "Y")
                {
                    item.Text = info.WhDbDesc + " ★ ";
                }
                else
                {
                    item.Text = info.WhDbDesc;
                }
                this.lbxAuthorizedWH.Items.Add(item);
            }
            this.lbxUnauthorizedWH.DataSource = userPermission.UnauthorizedWH;
            this.lbxUnauthorizedWH.DataTextField = "WhDbDesc";
            this.lbxUnauthorizedWH.DataValueField = "WhDbID";
            this.lbxUnauthorizedWH.DataBind();
        }

        private void SetUserPermissionsInfo2Form(string userID)
        {
            try
            {
                UserPermissionsInfo userPermissions = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(userID, "USER_PERMISSIONS") as UserPermissionsInfo;
                base.PageQueryEntitySession = userPermissions;
                if (userPermissions != null)
                {
                    this.txtUserID.Text = userPermissions.UserID;
                }
                this.SetControlsGvRoleData(userPermissions);
                this.SetControlslbxWhData(userPermissions);
                this.SetControlslbxOwnerData(userPermissions);
                this.SetControlslbxCustomerData(userPermissions);
                this.SetControlslbxVendorData(userPermissions);
                this.SetControlslbxCarrierData(userPermissions);
                this.SetControlslbxBillingEntityData(userPermissions);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void SetUserPermissionsInfo3From()
        {
            UserPermissionsInfo userPermissions = base.PageQueryEntitySession as UserPermissionsInfo;
            this.txtUserID.Text = userPermissions.UserID;
            this.SetControlsGvRoleData(userPermissions);
            this.SetControlslbxWhData(userPermissions);
            this.SetControlslbxOwnerData(userPermissions);
            this.SetControlslbxCustomerData(userPermissions);
            this.SetControlslbxVendorData(userPermissions);
            this.SetControlslbxCarrierData(userPermissions);
            this.SetControlslbxBillingEntityData(userPermissions);
        }
    }
}

